const db = wx.cloud.database();
const swiperImgUrls = db.collection('swiper')
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    background_color: "#f2c512",
    background_color1: "#f2c512",
    background_color2: "#000000",
    background_color3: "#f4c2c2",
    background_color4: "#fce6c9",
    background_color5: "#9999FF",
    text_color: "#ffffff",
    navtitle:"考研上岸室",
    navtitle1: "考研上岸室",
    navtitle2: "六级冲刺班",
    navtitle3: "司考必过班",
    navtitle4: "雅思进修班",
    showroom1: false,
    showroom2: false,
    showroom3: false,
    showroom4: false,
    
    
    swiperImgUrls: [
      /*
      {                  
        images:'cloud://bluewave-7co1p.626c-bluewave-7co1p-1301720800/swiper/img5.png', 
        url: '../../packageB/pages/instruction/instruction',
      },
      {                  
        images:'cloud://bluewave-7co1p.626c-bluewave-7co1p-1301720800/swiper/img4.png', 
        url: '../../packageB/pages/computer/computer',
      },
      {                  
        images:'cloud://bluewave-7co1p.626c-bluewave-7co1p-1301720800/swiper/img1.jpg', 
        //url: '../../pages/instruction/instruction'
      },
      {                  
        images:'cloud://bluewave-7co1p.626c-bluewave-7co1p-1301720800/swiper/img2.jpg', 
        //url: '../../pages/instruction/instruction',
      },
      {                  
        images:'cloud://bluewave-7co1p.626c-bluewave-7co1p-1301720800/swiper/img7.jpg', 
        //url: '../../packageB/pages/img7-xingguang/img7',
      },*/
    ],
    swiperIndex: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.getImages()
    //console.log(this.data.swiperImgUrls)
    var start_time = new Date();
    var h = start_time.getHours();
    //console.log(h);
    if(h>18 || h<6){
      this.setData({
        shownight: true,
        showday: false,
      })
    }else{
      this.setData({
        shownight: false,
        showday: true,
      })
    }
  },

  getImages(){
    swiperImgUrls.get({
      success:res=>{
        //console.log("请求成功", res)
        this.setData({
          swiperImgUrls: res.data[0].swiperImgUrls
        })
      },
      fail(res) {
        console.log("请求失败", res)
      }

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '高颜值自习神器 Learn 随处',
      imageUrl: 'cloud://bluewave-7co1p.626c-bluewave-7co1p-1301720800/image/room.jpg'
    }
  },


  swiperChange(e) {
    const that = this;
    that.setData({
      swiperIndex: e.detail.current,
    })
  },
  OnJump:function(e){ //点击图片触发的事件
    //console.log(e)    // 查看标签上的属性
    var url = e.currentTarget.dataset.url // 取出标签上绑定的 url
    wx.navigateTo({ // 不关闭当前页面，跳转到非tarber页面
      url: url,
    })
  },

  changeBackgroundColor: function(e) {
    //console.log(e)
    this.setData({
      background_color: this.data.background_color1
    })
  },

  changeBackgroundColor2: function(e) {
    this.setData({
      background_color: this.data.background_color2
    })
  },

  changeBackgroundColor3: function(e) {
    this.setData({
      background_color: this.data.background_color3
    })
  },

  changeBackgroundColor4: function(e) {
    this.setData({
      background_color: this.data.background_color4
    })
  },

  changeBackgroundColor5: function(e) {
    this.setData({
      background_color: this.data.background_color5
    })
  },

  chooseroom1: function(e) {
    this.setData({
      navtitle: this.data.navtitle1,
      showroom1: true,
      showroom2: false,
      showroom3: false,
      showroom4: false,
    })
  },
  cancelroom1: function(e) {
    this.setData({
      showroom1: false
    })
  },
  

  chooseroom2: function(e) {
    this.setData({
      navtitle: this.data.navtitle2,
      showroom2: true,
      showroom1: false,
      showroom3: false,
      showroom4: false,
    })
  },
  cancelroom2: function(e) {
    this.setData({
      showroom2: false
    })
  },
  chooseroom3: function(e) {
    this.setData({
      navtitle: this.data.navtitle3,
      showroom3: true,
      showroom2: false,
      showroom1: false,
      showroom4: false,
    })
  },
  cancelroom3: function(e) {
    this.setData({
      showroom3: false
    })
  },
  chooseroom4: function(e) {
    this.setData({
      navtitle: this.data.navtitle4,
      showroom4: true,
      showroom2: false,
      showroom3: false,
      showroom1: false,
    })
  },
  cancelroom4: function(e) {
    this.setData({
      showroom4: false
    })
  },


  moreBtn: function () {
    this.plus();
  },
  //点击弹出
  plus: function () {
    if (!this.data.isPopping) {
      //弹出
      this.popp();
      this.setData({
        isPopping: true
      })
      }
    else {
   
      //缩回
      this.takeback();
      this.setData({
        isPopping: false
      });
      // console.log("弹出")
    }
  },  
  //弹出动画
  popp: function () {
    //plus顺时针旋转
    let animationPlus = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease'
    })
    let animationcollect = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease'
    })
    let animationTranspond = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease'
    })
    let animationInput = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease'
    })
    let animationEgg = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease'
    })
    let animationPurple = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease'
    })
    animationPlus.rotateZ(180).step();
    animationcollect.translate(-0, -100).rotateZ(0).opacity(1).step();
    animationTranspond.translate(-0, -150).rotateZ(0).opacity(1).step();
    animationInput.translate(-0, -200).rotateZ(0).opacity(1).step();
    animationEgg.translate(-0, -250).rotateZ(0).opacity(1).step();
    animationPurple.translate(-0, -300).rotateZ(0).opacity(1).step();
    this.setData({
      animPlus: animationPlus.export(),
      animCollect: animationcollect.export(),
      animTranspond: animationTranspond.export(),
      animInput: animationInput.export(),
      animEgg:animationEgg.export(),
      animPurple:animationPurple.export(),
    })
  },
  //收回动画
  takeback: function () {
    //plus逆时针旋转
    let animationPlus = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease'
    })
    let animationcollect = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease'
    })
    let animationTranspond = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease'
    })
    let animationInput = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease'
    })
    let animationEgg = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease'
    })
    let animationPurple = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease'
    })
    animationPlus.rotateZ(0).step();
    animationcollect.translate(0, 0).rotateZ(0).opacity(0).step();
    animationTranspond.translate(0, 0).rotateZ(0).opacity(0).step();
    animationInput.translate(0, 0).rotateZ(0).opacity(0).step();
    animationEgg.translate(0, 0).rotateZ(0).opacity(0).step();
    animationPurple.translate(0, 0).rotateZ(0).opacity(0).step();
    this.setData({
      animPlus: animationPlus.export(),
      animCollect: animationcollect.export(),
      animTranspond: animationTranspond.export(),
      animInput: animationInput.export(),
      animEgg:animationEgg.export(),
      animPurple:animationPurple.export(),
    })
  },
  changeday(){
    //console.log(h);
    if(this.data.showday == false){
      this.setData({
        shownight: false,
        showday: true,
      })
    }else{
      this.setData({
        shownight: true,
        showday: false,
      })
    }
  },

  goToClock: function() {
    var text_color = this.data.text_color;
    var background_color = this.data.background_color;
    var navtitle = this.data.navtitle;

    wx.navigateTo({
      url: './FS_clock?text_color=' + text_color + '&background_color=' + background_color + '&navtitle=' + navtitle,
    })
    
  },

})